const fn = (arr, key) => {
  let left = 0;
  let right = key;
  let res = [];
  let len = arr.length;
  while (right <= len) {
    let curArr = arr.slice(left, right);
    curArr.sort();
    res.push(curArr[curArr.length - 1]);
    left++;
    right++;
  }
  return res;
};

console.log(fn([1, 3, -1, -3, 5, 3, 6, 7], 3));
  